//
//  QZMyBalanceController.m
//  WeiWeiHaircut
//
//  Created by 超群 on 15/10/15.
//  Copyright © 2015年 超群. All rights reserved.
//

#import "QZMyBalanceController.h"
#import "QZMyBalanceCell.h"
#import "QZMyMonthCell.h"
#import "QZMyLotteryCell.h"
#import "QZAddMoneyVC.h"
@interface QZMyBalanceController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UITableView *mainView;
@end

@implementation QZMyBalanceController{
    NSString * _purseSum;//余额
    NSInteger _monthCard;//月卡
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [self downloadDatas];
}
- (void)viewDidLoad {

    [super viewDidLoad];
    self.navigationItem.title = @"钱包";
    [self createTable];
    [self addBtnOnNavWithTitle:@"我" andImageName:@"返回" andTarget:self andAction:@selector(backAction) andFrame:CGRectMake(0, 0, 30, 20) andDirection:left];
  
}
-(void)downloadDatas{
    NSString *url  =[NSString stringWithFormat:@"%@%@",newPublicURL,@"Purse.GetUserPurse"];
    [self.request QZRequest_POST:url parameters:@{@"user_id":[QZUserInfo userId]} tagNSString:@"获取钱包信息" stopRequest:NO isSerializer:NO isCache:NO];
    
    
}
-(void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)createTable{
    self.view.backgroundColor = BACKGROUDCOLOR;
    
    _mainView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-49) style:UITableViewStylePlain];
    _mainView.backgroundColor = BACKGROUDCOLOR;
    _mainView.delegate = self;
    _mainView.dataSource =self;
    _mainView.separatorStyle = NO;

    [self.view addSubview:_mainView];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
   
        static NSString *cellID = @"QZMyBalanceCell";
        QZMyBalanceCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if (cell == nil) {
            cell = [[QZMyBalanceCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
            cell.myBlick = ^(UIButton *btn){
                QZAddMoneyVC *money = [[QZAddMoneyVC alloc] initWithNibName:@"QZAddMoneyVC" bundle:nil];
                [self.navigationController pushViewController:money animated:YES];
            };
           
         }
 
    
        static NSString *cellID2 = @"QZMyMonthCell";
        QZMyMonthCell *cell2 = [tableView dequeueReusableCellWithIdentifier:cellID2];
        if (cell2 == nil) {
            cell2 = [[QZMyMonthCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID2];
            cell2.price.text = [NSString stringWithFormat:@"%ld",_monthCard];
        }
    
        static NSString *cellID3 = @"QZMyLotteryCell";
        QZMyLotteryCell *cell3 = [tableView dequeueReusableCellWithIdentifier:cellID2];
        if (cell3 == nil) {
            cell3 = [[QZMyLotteryCell alloc] initWithStyle:UITableViewCellStyleDefault      reuseIdentifier:cellID3];
        }
 
    
    if (indexPath.row == 0) {
         cell.price.text = _purseSum;
        return cell;
    }
    if (indexPath.row == 1) {
        return cell2;
    }
    if (indexPath.row == 2) {
        return cell3;
    }
    
   
    return cell;
    
    
}
-(void)request_POST_FinishValue:(id)value tagNSString:(NSString *)tag{
    if ([tag isEqualToString:@"获取钱包信息"]) {
        /*
         data.purse_sum	整型	用户余额
         data.month_card	整型	月卡
         */
        _purseSum = nil;
        _monthCard = 0;
        if ([value[@"data"][@"status"] integerValue] == 100) {
           NSDictionary *dic = value[@"data"][@"data"];
            _purseSum = dic[@"purse_sum"];
            _monthCard = [dic[@"data.month_card"] integerValue];
            [self.mainView reloadData];
        }
        
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 80;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
